Tag Archives: Tutorial

Send data to Thinkspeak with ESP8266 by AT command

Published by:

In this experiment, by using AT commands we tried to connect our ESP8266 to Wi-fi, then send a data to Thingspeak.com website.

+ 

  • On Thingspeak website:

 

  • Read the 1st report and make the wiring as explained in that report.
  • Us following AT commands to connect to Thinkspeak
    • AT+CIPSTART=”TCP”,”api.thingspeak.com”,80
    • AT+CIPSEND=51
    • GET /update?key=YOUR_ API_Key&field1=YOUR_DATA_like_100 \r\n
    • AT+CIPCLOSE

Note:

AT+CIPSTART commands starts a TCP or UDP connection.

Parameters
– 0..7 – Connection number
– “TCP” or “UDP”
– Remote server IP address
– Remote server port
– remote domain name

AT+CIPSEND AT command is used to send the data over the TCP or UDP connection.

Usage:
AT+CIPSEND? = This returns the data length sent at a time

AT+CIPCLOSE AT command closes the TCP or UDP connection. It can be configured for slow close or quick close. When there are multi-IP connections, a connection number is also required.

 

 

Congratulations! You send data to Thinkspeak.

 

 

 

Direct use of ESP8266 WiFi module

Published by:

In this experiment, we tried to find out:
1- What is the ESP8266 Wi-Fi module?
2- ESP8266 Pin Configuration
3- How to use the ESP8266 Wi-Fi module without using any other microcontroller.

What is the ESP8266 Wi-Fi module?
The ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capability. It requires power Supply of +3.3V where current Consumption is 100mA and 10uA during the operation and during deep sleep respectively. I/O Voltage is 3.6V (max) and I/O source current is 12mA (max). ESP8266 has a built-in low power 32-bit MCU which operates at 80MHz. It has a 512kB Flash Memory. ESP8266 Wi-Fi module can be used as Station or Access Point or both combined in different IoT applications. Since this module supports serial communication, therefore, it is compatible with many development platforms like Arduino. Arduino IDE or AT-commands or Lua Script are used for programming this powerful module.

ESP8266 Pin Configuration:

Pin Number 1 is named Ground. This pin is used to connect to the ground of the circuit.
Pin Number 2 is named TX or GPIO – 1. This pin is used to connect to the RX pin of programmer/uC to upload program and can act as a general purpose Input/output pin when not used as TX.
Pin Number 3 is named GPIO-2. This pin is used as a general purpose Input/output pin.
Pin Number 4 is named CH_EN This pin is used for Chip enabling – Active high.
Pin Number 5 is named GPIO – 0 or Flash. This pin is used as a general purpose Input/output pin. This pin takes module into serial programming when held low during startup.
Pin Number 6 is named Reset. This pin is used to resets the module.
Pin Number 7 is named RX or GPIO – 3. This pin is used as a general purpose Input/output pin and Can act as a general purpose Input/output pin when not used as RX.
Pin Number 8 is named Vcc, This pin is used to Connect to +3.3V.

How to use the ESP8266 Wi-Fi module without using any other microcontroller.

To connect the ESP8266 to the computer we need a specific adapter. TTY adapter which is a USB Serial can be used for this purpose. But in this study, we used the Arduino Uno as a Bridge to talk with the module directly.
Note: By bypassing everything in the Uno we used it as a bridge. Connect the reset pin on the Arduino Uno to GND to bypass its bootloader.

1 – wired the ESP8266 and Arduino Uno as follows:

  • connecting RESET of Uno to GND of Uno  (to bypass everything in the Uno)
  • connect the TX of ESP8266 to the TX of Uno
  • Connect the RX of ESP8266 to the RX of Uno
  • GND of ESP8266 to GND of Uno
  • VCC and CH_PD of ESP8266 to 5v of Uno
  • connect Arduino to the computer

2 – open the Arduino Serial Monitor in the Arduino IDE.

  • Choose “Both NL & CL” on
  • Adjust the Baud rate on 115200 or 9600.
  • Now start to send AT commands as follows:
    • To check if it is working type AT in Serial Monitor and get OK response:
      ——————————–
      AT
    • If  you get OK, set the WiFi mode as station mode (client) as follows:
      ——————————–
      AT+CWMODE=1
    • you can list the Wireless AP with the following command:
      ——————————–
      AT+CWLAP
    • Join the network
      ——————————–
      AT+CWJAP=”WIFI_NAME”,”WIFI_PASWORD”

Congratulations! You connected to the network.

 

 

ARDUINO UNO Project 05: Mood Cue

Published by:

ARDUINO UNO Project 05: Mood Cue

Ingredients :

1- potentiometer       #1

2- capacitor 100µF    #2

3- Servo motor         #1

 

BUILD THE CIRCUIT

ARDUINO UNO Project 05: Mood Cue

 

 

Code:

#include <Servo.h>
Servo TestServo;
int const potPin=A0;
int potValue;
int angle;
void setup() {
TestServo.attach(9);
Serial.begin(9600);

}

void loop() {
potValue=analogRead(potPin);
Serial.print(“potValue: “);
Serial.print(potValue);
angle=map(potValue, 0,1023,0,179);
Serial.print(“,angle: “);
Serial.println(angle);
TestServo.write(angle);
delay(15);
}

ARDUINO UNO Project 04: Color Mixing Lamp

Published by:

Ingredients :

1- RGB LED                   #1

2- Phototransistor         #3

3- Resistor   220Ω         #3

4- Resistor   10KΩ         #3

5- Gel Red                    #1

6- Gel Green                 #1

7- Gel Blue                    #1

8- Wire

BUILD THE CIRCUIT

ARDUINO UNO Project 04: Color Mixing Lamp

ARDUINO UNO Project 04: Color Mixing Lamp

ARDUINO UNO Project 04: Color Mixing Lamp

ARDUINO UNO Project 04: Color Mixing Lamp

Code:
const int greenLEDPin=9;
const int blueLEDPin=10;
const int redLEDPin=11;

const int redSensorPin=A0;
const int greenSensorPin=A1;
const int blueSensorPin=A2;

int redValue=0;
int greenValue=0;
int blueValue=0;

int redSensorValue=0;
int greenSensorValue=0;
int blueSensorValue=0;

void setup() {
Serial.begin(9600);

pinMode(greenLEDPin,OUTPUT);
pinMode(blueLEDPin,OUTPUT);
pinMode(redLEDPin,OUTPUT);
}

void loop() {
redSensorValue=analogRead(redSensorPin);
delay(5);
greenSensorValue=analogRead(greenSensorPin);
delay(5);
blueSensorValue=analogRead(blueSensorPin);

Serial.print(“Raw Sensor Value \t red: “);
Serial.print(redSensorValue);
Serial.print(” \t green: “);
Serial.print(greenSensorValue);
Serial.print(” \t blue: “);
Serial.println(blueSensorValue);

redValue=redSensorValue/4;
greenValue=greenSensorValue/4;
blueValue=blueSensorValue/4;

Serial.print(“Maped Sensor Value \t red: “);
Serial.print(redValue);
Serial.print(” \t green: “);
Serial.print(greenValue);
Serial.print(” \t blue: “);
Serial.println(blueValue);

analogWrite(redLEDPin,redValue);
analogWrite(greenLEDPin,greenValue);
analogWrite(blueLEDPin,blueValue);

}

C Programming Tutorial – 18 – ++ in Left and Right:

Published by:

Note:

  • // ++ in left first add 1 to viable and then calculate the equation. 
  • // ++ in right first calculate the equation and then add 1 to viable .

Code:
—————————

#include <stdio.h>
#include <stdlib.h>

int main()
{

int IncResult, increment=5 , constant=4;

// ++ in left first add 1 to increment and then calculate the equation.
IncResult = ++increment *constant;
printf(“increment = %d and constant= %d so IncResult= %d \n”,increment ,constant ,IncResult );

// since we defined the variable previously so we do not need to define them again.

IncResult=0 , increment=5 , constant=4;

// ++ in right first calculate the equation and then add 1 to increment

IncResult = increment++ *constant;
printf(“increment = %d and constant= %d so IncResult= %d \n”,increment ,constant ,IncResult );

return 0;

}

C Programming Tutorial – 17 – Short form of if + add a string :

Published by:

Note:

  • //Example for Short form of if+add a string

Code:
—————————

#include <stdio.h>
#include <stdlib.h>

int main()
{

int friends;
printf(“How many friends do you have ? \n”);
scanf(” %d”, &friends);

// If you have 0 or 2 or 3 or … friends it shows s else if you have 1 friend you will not see s.
printf(“You have %d friend%s \n”, friends ,(friends !=1 ) ? “s” : “”);

return 0;

}

C Programming Tutorial – 15 – Extract a character from an array + compare it with a character :

Published by:

Note:

  • //lastname[3] : Extract the 4th (not the 3rd) character of array lastname.
  • //lastname[3] > ‘M’   : compare the 4th character with character M.

Code:
—————————

#include <stdio.h>
#include <stdlib.h>

int main()
{

char lastname[20];
printf(“Enter your last name ? \n”);
scanf(” %s”, lastname);
if (lastname[3] > ‘M’) { // character extract and character comparison.
printf(“You are in team Blue \n”);
} else {
printf(“You are in team Red \n”);
}

return 0;

}

C Programming Tutorial – 14 – if – else if :

Published by:

Code:
—————————

#include <stdio.h>
#include <stdlib.h>

int main()
{

float agrade,bgrade,cgrade;
printf(“Please enter you 3 grades. \n”);
scanf(” %f”, &agrade); // You should not use \n in scanf. !!!!
scanf(” %f”, &bgrade);
scanf(” %f”, &cgrade);
float averagegarde = (agrade+bgrade+cgrade)/3;
printf(“Your average grade is : %.2f \n”,averagegarde);
if (averagegarde>=90){ // Use of else if
printf(“Your FINAL grade is A. \n”);
} else if (averagegarde>= 80) {
printf(“Your FINAL grade is B. \n”);
} else if (averagegarde>= 70){
printf(“Your FINAL grade is C. \n”);
} else {
printf(“You could not pass the course ! \n”);
}
if ((agrade>=90) && (bgrade>=80) && (cgrade>=70)){       // In this part we compare more 1 values and use logic syntax like && ||
printf(“You can enter to Final EXAM.\n”);
} else
{
printf(“You cannot enter to Final exam !\n”);}

return 0;

}

C Programming Tutorial – 13 – if :

Published by:

Code:
—————————

#include <stdio.h>
#include <stdlib.h>

int main()
{

int Yourage;
char gender;
printf(“How old are you?\n”);
scanf(” %d”,&Yourage);
printf(“what is your gender? (m/f)\n”);
scanf(” %c”,&gender);

if(Yourage>=18)
{
if(gender == ‘m’) // compare the char value
{
printf(“welcome dude !\n”);
}

if(gender == ‘f’)
{
printf(“welcome m’lady !\n”);
}

}

if(Yourage <18)
{
printf(“You can not visit this website.\n”);
}

return 0;

}