Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.
Home » Computer Science » IoT Lab » Analog Input and Output using NodeMCU ESP8266
Suryateja Pericherla Categories: IoT Lab. No Comments on Analog Input and Output using NodeMCU ESP8266
0
(0)

In this article we will learn to implement analog input and output using NodeMCU ESP8266. If your are new to Internet of Things (IoT), learn about IoT by visiting our Internet of Things tutorial for beginners.

 

Aim of Experiment

To implement analog input output.

 

Components Required

  • NodeMCU – 1
  • 100 kΩ Potentiometer – 1
  • LED – 1
  • 330 Ω Resistor – 1
  • Breadboard – 1

 

Connections Diagram (Schematic)

Analog Input and Output using NodeMCU ESP8266

 


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


Code (C++/Arduino IDE)

// Pins
const int pot_pin = A0;
const int led_pin = D0;

void setup() {
  pinMode(led_pin, OUTPUT);
  pinMode(pot_pin, INPUT);
}

void loop() {
  
  // Read knob value (0 - 1023)
  int val = analogRead(pot_pin);
  
  // Convert knob value to PWM value (0 - 255)
  int brightness = map(val, 0, 1023, 0, 255);
  
  // Set LED brightness
  analogWrite(led_pin, brightness);
}

 

Video Explanation

 

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
Pinterest
Youtube
Instagram
Blogarama - Blog Directory