Skip to main content

Posts

Showing posts from January, 2017

Make an real-time IoT temperature sensor with thingSpeak and ESP8266

#include <ESP8266WiFi.h> #include <DHT.h> //////////////////////////////////////////////////////////////////////////////////////////////////////////// #define DHTPIN 2 // what pin we’re connected to String apiKey = "yourAPIKey"; //API key from ThingSpeak channel const char* ssid = "WifiSSID"; //SSID of your wifi const char* password = "password123"; //password of your wifi int duration=5;//delay between each data measure and uploading //////////////////////////////////////////////////////////////////////////////////////////////////////////// const char* server = "api.thingspeak.com"; DHT dht(DHTPIN, DHT11, 15);// Start DHT sensor WiFiClient client; //Start clinet void setup() {   Serial.begin(115200);   dht.begin();   WiFi.begin(ssid, password);   Serial.println();   Serial.println();   Serial.print("Connecting to ");   Serial.println(ssid);   WiFi.begin(ssid, password);   while (WiFi.status() !...

Connect Arduino Wemos D1 ESP8266 to Internet/Wi-Fi Router

Connect ESP8266 to Wi-Fi Router Upload these code to your Arduino WeMos D1 ESP8266 W-Fi board. #include <ESP8266WiFi.h> //SSID of your network char ssid[] = " myRouter"; //SSID of your Wi-Fi router char pass[] = " myPassWord"; //Password of your Wi-Fi router void setup() {   Serial.begin(115200);   delay(10);   // Connect to Wi-Fi network   Serial.println();   Serial.println();   Serial.print("Connecting to...");   Serial.println(ssid);   WiFi.begin(ssid, pass);   while ( WiFi.status() != WL_CONNECTED) {     delay(500);     Serial.print(".");   }   Serial.println("");   Serial.println("Wi-Fi connected successfully"); } void loop ( ) {} Using ESP8266 to connect to Wi-Fi need to use the function of: WiFi.begin(ssid, pass); // connect to target Wi-Fi SSID is the name of the Wi-Fi you want to connect to.  while ( ...

First look at Arduino D1 ESP8266 board

  First Look at Arduino D1 board Recently, I got the Arduino D1 board with ESP 8266 Wifi chip on it for about 8 USD. Instead of using ATmega 328, it’s an ESP8266-based Wi-Fi enable microprocessor. It also comes with 11 digital input/output pins , 1 analog input , micro usb connect and power jack which can be supplied with 9-24V of power input. Board connection ( CH340G) This board use CH340G USB to UART chip for USB connection  If you find your computer cannot recognize the device when you first plug in the D1 board, please try to download and install the CH340 drive for the USB to UART connection. CH340 USB to UART driver https://www.wemos.cc/downloads My Video of CH340 driver installation process https://www.youtube.com/watch?v=oCZJbKoni6M& The advantage of this integrated board is that it can be programmed like an Arduino, but with the ability to do some wireless data transmitting things. How fantastic it is to have such an affordable Wi-Fi b...

Sprintf function in Arduino

Arduino doesn’t support printf function like C and C++. Which makes formatting string with numbers a little bit harder. But there’s a few ways to generate similar effect. Using char buffer and sprintf int height = 8223; char buffer [ 100]; void setup ( ) {   Serial . begin ( 9600);   sprintf ( buffer, " Aconcagua is %d metres height.", height);   Serial . println ( buffer); } void loop ( ) { } Create a char buffer and use sprintf to format text with int numbers. However, the sad thing is that this method does not support float , double and long long . Using String with println Another way to join the string with an integer or float number together is by adding String ( “”) into your println ( ) function. Which will make string and float number join together. float height = 8223.05; void setup ( ) {   Serial . begin ( 9600);   Serial . println ( String ( "") + " Aconcagua is " + height + ...

Arduino Serial Communication (I)

What is Serial communication for ? If you are looking for some way to make your Arduino talk with other devices or to be able to be controlled by your computer, then you should have a look of serial communication! Serial is used for communication between the Arduino board and a computer or other devices.   Serial communication is a kind of “way” for devices to talk to each other. For example, if you build a temperature sensing Arduino project, and wanted to transmit data to the computer. Or controlling LED light on Arduino by computer. Then you might find it useful. Let’s try some simple code with serial communication. Open your Arduino IDE and upload these codes. void setup() {   Serial.begin(9600);   Serial.println("Hello Aconcagua!"); } void loop() { } Click on the Serial Monitor button on the right hand site.   If everything goes well. Hello Aconcagua! will be printed on the your serial monitor screen.   If you see any "Align ...

Arduino Nano connection error (CH340/CH340G driver)

Recently, I’ve got some cheap Arduino Nano from Internet for about 5 USD. However, I was struggle with the connection issues that my Arduino program cannot regonize my Nano chips. The error message is kind of like this And I found out that the new Arduino nano has a different USB connection chip which is CH340G compared to the previous FTDI one. The new nano(left) and the old one I bought have some different chip layout. After installing the driver from the manufacture from China, the problem finally sloved. You can download the driver from here if you have encounter the same problem. WCH CH340G driver   Just click on the download button. For Mac and Linux I think this two file might work! https://youtu.be/jZElNvcHmMk