Answered step by step
Verified Expert Solution
Question
1 Approved Answer
SOURCE CODE: #include #include #include 9 | P a g e const char * ssid = Galaxy A 3 1 EB 6 1 ;
SOURCE CODE:
#include
#include
#include
P a g e
const char ssid "Galaxy AEB;
const char password "mutyam@;
const String validQRCode "validqrcode";
const String validQRCode "validqrcode;
WebServer server;
Define the DC motor pins for the first motor on LN
const int ENA ; PWM pin for speed control
const int IN; Direction pin
const int IN; Direction pin
Define the DC motor pins for the second motor on LN
const int ENB ; PWM pin for speed control
const int IN; Direction pin
const int IN; Direction pin
void handleRoot;
void handleQRRequest; Declare the handleQRRequest function
void setup
Serial.begin;
WiFi.beginssid password;
while WiFistatus WLCONNECTED
delay;
Serial.printlnConnecting to WiFi...";
Serial.printlnWiFi connected";
Serial.printIP address: ;
Serial.printlnWiFilocalIP;
if MDNSbeginesp
Serial.printlnError setting up MDNS responder!";
while
delay;
Serial.printlnMDNS responder started";
P a g e
Set the motor control pins as outputs
pinModeENA OUTPUT;
pinModeIN OUTPUT;
pinModeIN OUTPUT;
pinModeENB OUTPUT;
pinModeIN OUTPUT;
pinModeIN OUTPUT;
server.on handleRoot;
server.onqr handleQRRequest; Now handleQRRequest is declared
server.begin;
MDNSaddServicehttptcp;
Serial.printlnHTTP server started";
void loop
server.handleClient;
bool validateQRCodeString qrData
return qrData.equalsvalidQRCode qrData.equalsvalidQRCode;
void dispenseItemString qrData, int tablets
Serial.printlnDispensing item...";
int rotationTime ; Adjust this time based on your motor speed to achieve a degree
rotation
int rotations tablets; Each tablet corresponds to one rotation
Rotate the appropriate motor based on the QR code
for int i ; i rotations; i
if qrDataequalsvalidQRCode
Motor
digitalWriteIN HIGH; Set motor direction
digitalWriteIN LOW;
analogWriteENA; Set motor speed to maximum
else if qrDataequalsvalidQRCode
Motor
digitalWriteIN HIGH; Set motor direction
digitalWriteIN LOW;
analogWriteENB; Set motor speed to maximum
P a g e
delayrotationTime; Wait for the motors to complete one rotation
if qrDataequalsvalidQRCode
analogWriteENA; Stop motor
else if qrDataequalsvalidQRCode
analogWriteENB; Stop motor
delay; Wait before the next rotation
Serial.printlnItem dispensed";
void handleQRCodeString qrData, int tablets
if validateQRCodeqrData
Serial.printlnQR Data is valid";
dispenseItemqrData tablets;
else
Serial.printlnQR Data is invalid";
void handleQRRequest
if serverargs
String qrData ;
int tablets ; Default to tablet if not specified
for uintt i ; i server.args; i
if serverargNameiqr
qrData server.argi;
if serverargNamei "tablets"
tablets server.argitoInt;
handleQRCodeqrData tablets;
server.send "textplainQR Code processed";
void handleRoot
P a g e
const char webpage PROGMEM R
Tablet Dispenser
Press the button to dispense an item:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started