Tom van Loon
Published © CC BY

Adding a switch to nodeMCU and Thingspeak

Switching is a major part of any IoT project and I will explain how I used a water level switch.

BeginnerProtip24 minutes2,242
Adding a switch to nodeMCU and Thingspeak

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
CI Blue 0.9 Version
×1
Resistor 4.75k ohm
Resistor 4.75k ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE
Version 1.6.4

Story

Read more

Schematics

Schematic

Output

Code

Switch

C/C++
Copy blocks ONLY
// Part of INI
// LEVEL sensor part
float level = 0;
const int levelPin = 14; // the number of the pushbutton pin ( D5 )
int buttonState = 0;


// Part of SETUP
// LEVEL sensor input
  pinMode(levelPin, INPUT);
  

// Part of MAIN LOOP
// Read LEVEL sensor
    buttonState = digitalRead(levelPin);

    if (buttonState == HIGH) {
      // turn level high
    level = 250;
    }
    else {
      // turn level low
    level = 10;

    
// Part of Thingspeak post routine
           postStr +="&field4=";
           postStr += String(level);
           
    

Credits

Tom van Loon

Tom van Loon

3 projects • 1 follower
Sr Test Technician - OPS
Thanks to Jeroen Beemster and diy_bloke.

Comments