Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ESP8266 Internet of Things Cookbook

You're reading from   ESP8266 Internet of Things Cookbook Over 50 recipes to help you master ESP8266 functionality

Arrow left icon
Product type Paperback
Published in Apr 2017
Publisher Packt
ISBN-13 9781787288102
Length 268 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Marco Schwartz Marco Schwartz
Author Profile Icon Marco Schwartz
Marco Schwartz
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Configuring the ESP8266 FREE CHAPTER 2. Your First ESP8266 Projects 3. More ESP8266 Functions 4. Using MicroPython on the ESP8266 5. Cloud Data Monitoring 6. Interacting with Web Services 7. Machine to Machine Interactions Index

Reading analog signals


The ESP8266 has one analog pin that we can use to read analog signals. In this recipe, we will be looking at how to write a sketch that reads analog signals. This will enable us to read input from analog sensors.

Getting ready

Connect your ESP8266 board to your computer via a USB cable and set up your Arduino IDE (refer back to Chapter 1, Configuring the ESP8266). Once that is done, you can proceed to make the other connections.

In this recipe, we will need a breadboard and jumper wires in addition to the ESP8266 board. Mount the ESP8266 board onto the breadboard and then connect a jumper wire from the analog ADC pin to the GND pin. The connection should be as shown in the following diagram:

How to do it…

We will use the analogRead() function to read the analog signal on the ADC pin and display the analog signal value on the serial monitor. This will be repeated every 1 second:

// LED pin
int val = 0;

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

void loop() {
  
  // read pin...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime