How To Post On Twitter From Arduino and ESP8266 IoT Project
Twitter is a free social platform that can be very useful for your IoT project. You can use it instead of paying for a messaging platform.
In this project, I will teach you how to use Twitter to send temperature alerts from your IoT project. The project utilizes ESP8266 WiFi module to connect Arduino to the internet.
The WiFi module connects to your home WiFi for the internet. You can also use the ESP8266 alone but in this simple project, we shall use it together with Arduino Uno. For integration with Twitter, we use Thingspeak’s ThingTweet App. We connect to it via an API.
ThingTweet is a Twitter integration app built by ThingSpeak that allows your IoT project to send tweet messages. You can use the App to send alerts via Twitter.
For example, you can send an alert when the temperature in your room reaches a certain value. In this post, you will learn how to integrate your Twitter account with ThingSpeak through the ThingTweet app and post your first tweet alert when the temperature reading on TPM36 sensor exceeds 29 degrees Celcius
Project requirements
- Arduino
- ESP8266
- 10k resistor
- Temperature sensor FTDI chip/ CP2102/Voltage divider
Assumptions: I am assuming you have connected your ESP8266 Wi-Fi Module and that your WiFi has internet connectivity.
Building the Circuit for the Simple IoT Project
The circuit for this project is very simple. Using the following schematic diagram to build your circuit.
Schematic Diagram

How to Link Twitter with ThingTweet in ThingSpeak





How the Project Works
How TMP36 Temperature Sensor Works
To measure temperature, I am using the TMP36 analog temperature sensor. This is a small solid-state, transistor-like chip that measures the ambient temperature. It uses the principle of proportionate increase of voltage across a diode with an increase in temperature. This voltage change is then amplified to produce a measurable analog voltage output. The ADC of the Arduino microcontroller detects this output signal and converts it to a 10-bit value.
The 10-bit output value is then multiplied with the ADC resolution to generate an equivalent voltage with respect to a 5V reference.
The formula for this calculation is Vout = (ADC output) x (Input voltage)/(1024).
We convert the voltage output degree Celcius using the formula: Temp in degree Celcius = ((Vout in mV) – (500mV offset voltage ))/10.
The 0.5V offset voltage is inherent in the output of the TMP36. For example, assuming the ADC output is 500, the Vout = (500 x 5V)/1024 = 2.441V This output voltage can be converted to degrees as follows: (2441 – 500)/10 = 194.1 degrees.
Arduino Sketch
How the Arduino Code Works
The code has two functional units. The first one is for reading the temperature as measured by the TMP36. The code works as described earlier in this post. The analog reading from the TMP36 temperature sensor is stored in the variable reading
. This reading is already converted to a 10-bit value by the ADC of Arduino.
The value is then mapped to a 5V input by multiplying with 5V and dividing by 1024 (the number of possible values). This value is then converted to equivalent degrees Celcius and stored in a float variable temperatureC
.
int reading = analogRead(sensorPin);
float voltage = reading * 5.0;
voltage /= 1024.0;
//Serial.print(voltage);
//Serial.println(" volts");
float temperatureC = (voltage - 0.5) * 100 ;
Serial.print(temperatureC);
Serial.println(" degrees C");
The second section involves the ESP8266. When the temperature exceeds 29 degrees, the ESP8266 initializes and sends an alert to Twitter via ThingTweet API of ThingSpeak.
The code starts by creating an HTTP POST structure using the function postRequest()
. This functions returns the POST structure in the form of a string and stores it in variable payload
.
The ESP8266 then creates a TCP connection to the Thingspeak server using the function tcp_connect()
. For TCP connection to be established, you need to pass the server IP address and port number. Once the TCP connection has been established, the alert is sent using the function postStatus()
.
Video: How to Post on Twitter from Arduino ESP8266 Project
In this video, you will learn how to send temperature alert messages on Twitter from an Arduino and ESP8266 IoT Project using Thingspeak’s ThingTweet App