Reader small image

You're reading from  Hands-On Internet of Things with MQTT

Product typeBook
Published inOct 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789341782
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Tim Pulver
Tim Pulver
author image
Tim Pulver

Tim Pulver is a Berlin-based freelance interaction designer and developer. In his work, he combines his physical prototyping experience and knowledge of interface design with modern technologies such as 3D printing, laser cutting, web technologies, and machine learning to create unique interactive experiences. In recent years, he has worked on interactive data visualizations, web-based audiovisual experiences, musical interfaces, and cables an innovative browser-based visual programming language that enables the creation of interactive audiovisual prototypes without writing any code. He holds a Bachelor of Arts degree in interface design from the University of Applied Sciences in Potsdam, Germany.
Read more about Tim Pulver

Right arrow

Controlling the servo motor via the Serial Monitor

In the previous section, we verified the following:

  • Whether the Arduino can connect to the internet
  • Whether the Arduino can send and receive MQTT messages via shiftr.io
  • Whether the motor is working

Now, let's create an interface to control the servo from the Serial Monitor. Create a new sketch and save it as ch5_01_servo_serial.

Delete the boilerplate code that is automatically added to new sketches (the empty setup and loop functions) and replace the contents of your editor with the following code:

#include <Servo.h>

Servo myservo;

void setup() {
Serial.begin(9600);
myservo.attach(9);
}

void loop() {
while (Serial.available() > 0) {
int inputValue = Serial.parseInt();
if (inputValue == 1) {
myservo.write(180);
} else {
myservo.write(0);
}
}
}

Let's go through the code to make sure...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Hands-On Internet of Things with MQTT
Published in: Oct 2019Publisher: PacktISBN-13: 9781789341782

Author (1)

author image
Tim Pulver

Tim Pulver is a Berlin-based freelance interaction designer and developer. In his work, he combines his physical prototyping experience and knowledge of interface design with modern technologies such as 3D printing, laser cutting, web technologies, and machine learning to create unique interactive experiences. In recent years, he has worked on interactive data visualizations, web-based audiovisual experiences, musical interfaces, and cables an innovative browser-based visual programming language that enables the creation of interactive audiovisual prototypes without writing any code. He holds a Bachelor of Arts degree in interface design from the University of Applied Sciences in Potsdam, Germany.
Read more about Tim Pulver