ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
>_ Things Lab
Connecting PHP with Arduino
Circuit
Arduino Code : Part 1
int led = 12;
void setup() {
// Open serial communications
Serial.begin(9600);
// send an intro:
Serial.println("0=off, 1=on");
Serial.println();
pinMode(led,OUTPUT);
}
Arduino Code : Part 2
void loop() {
// get any incoming bytes:
if (Serial.available() > 0) {
int input = Serial.read();
if (input == 48) { //received 0
digitalWrite(led,LOW);
}
else if (input == 49) { //received 1
digitalWrite(led,HIGH);
}
}
}
PHP code (same dir as "php_serial.class.php")
<?php
include "php_serial.class.php";
$msg = $argv[1]; // 0=off, 1=on
$serial = new phpSerial;
$serial->deviceSet("/dev/ttyUSB0");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->deviceOpen();
if (intval($msg)==0) $serial->sendMessage(0); //turn the led off
else $serial->sendMessage(1); //turn the led on
$serial->deviceClose();
?>
Running the code
? Upload code into Arduino
? Execute:
# get the PHP cli
sudo apt-get install php5-cli
php test.php [args] # run the program
? Pass 0 to turn the led off, or others to turn it
on
Ad

Recommended

Controlling Arduino With PHP
Controlling Arduino With PHP
Thomas Weinert
?
An introduction to PHP 5.4
An introduction to PHP 5.4
Giovanni Derks
?
NYU hacknight, april 6, 2016
NYU hacknight, april 6, 2016
Mikhail Sosonkin
?
ZeroNights: Automating iOS blackbox security scanning
ZeroNights: Automating iOS blackbox security scanning
Mikhail Sosonkin
?
Sniffing Mach Messages
Sniffing Mach Messages
Mikhail Sosonkin
?
Arp
Arp
Ebsil Sherly
?
Chat code
Chat code
manish bhandare
?
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
?
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber
?
swift-nio ¤Î¥¢©`¥­¥Æ¥¯¥Á¥ã©`¤È RxHttpClient
swift-nio ¤Î¥¢©`¥­¥Æ¥¯¥Á¥ã©`¤È RxHttpClient
Shinya Mochida
?
How to stand on the shoulders of giants
How to stand on the shoulders of giants
Ian Barber
?
Rop and it's friends
Rop and it's friends
nuc13us
?
20151224-games
20151224-games
Noritada Shimizu
?
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
Noritada Shimizu
?
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
Joseph Scott
?
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Masahiro Nagano
?
ZeroMQ Is The Answer
ZeroMQ Is The Answer
Ian Barber
?
Formatul Portable Executable
Formatul Portable Executable
DefCamp
?
Commencer avec le TDD
Commencer avec le TDD
Eric Hogue
?
Asyncio
Asyncio
Andrew Svetlov
?
§±§Ú§ê§Ö§Þ §Õ§Ý§ñ asyncio - §¡§ß§Õ§â§Ö§Û §³§Ó§Ö§ä§Ý§à§Ó, PyCon RU 2014
§±§Ú§ê§Ö§Þ §Õ§Ý§ñ asyncio - §¡§ß§Õ§â§Ö§Û §³§Ó§Ö§ä§Ý§à§Ó, PyCon RU 2014
it-people
?
Continuous testing In PHP
Continuous testing In PHP
Eric Hogue
?
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
Ian Barber
?
Ethical hacking with Python tools
Ethical hacking with Python tools
Jose Manuel Ortega Candel
?
Guarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous Testing
Eric Hogue
?
YCAM Workshop Part 3
YCAM Workshop Part 3
Shigeru Kobayashi
?
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
Nobuo Danjou
?
¥×¥í¥°¥é¥àŒgÐФλ°¤È?°¿³§¤È¥á¥â¥ê¤Î’¤¶¯¤Î»°
¥×¥í¥°¥é¥àŒgÐФλ°¤È?°¿³§¤È¥á¥â¥ê¤Î’¤¶¯¤Î»°
tatsunori ishikawa
?
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
Svet Ivantchev
?
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Demetrio Siragusa
?

More Related Content

What's hot (20)

Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber
?
swift-nio ¤Î¥¢©`¥­¥Æ¥¯¥Á¥ã©`¤È RxHttpClient
swift-nio ¤Î¥¢©`¥­¥Æ¥¯¥Á¥ã©`¤È RxHttpClient
Shinya Mochida
?
How to stand on the shoulders of giants
How to stand on the shoulders of giants
Ian Barber
?
Rop and it's friends
Rop and it's friends
nuc13us
?
20151224-games
20151224-games
Noritada Shimizu
?
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
Noritada Shimizu
?
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
Joseph Scott
?
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Masahiro Nagano
?
ZeroMQ Is The Answer
ZeroMQ Is The Answer
Ian Barber
?
Formatul Portable Executable
Formatul Portable Executable
DefCamp
?
Commencer avec le TDD
Commencer avec le TDD
Eric Hogue
?
Asyncio
Asyncio
Andrew Svetlov
?
§±§Ú§ê§Ö§Þ §Õ§Ý§ñ asyncio - §¡§ß§Õ§â§Ö§Û §³§Ó§Ö§ä§Ý§à§Ó, PyCon RU 2014
§±§Ú§ê§Ö§Þ §Õ§Ý§ñ asyncio - §¡§ß§Õ§â§Ö§Û §³§Ó§Ö§ä§Ý§à§Ó, PyCon RU 2014
it-people
?
Continuous testing In PHP
Continuous testing In PHP
Eric Hogue
?
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
Ian Barber
?
Ethical hacking with Python tools
Ethical hacking with Python tools
Jose Manuel Ortega Candel
?
Guarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous Testing
Eric Hogue
?
YCAM Workshop Part 3
YCAM Workshop Part 3
Shigeru Kobayashi
?
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
Nobuo Danjou
?
¥×¥í¥°¥é¥àŒgÐФλ°¤È?°¿³§¤È¥á¥â¥ê¤Î’¤¶¯¤Î»°
¥×¥í¥°¥é¥àŒgÐФλ°¤È?°¿³§¤È¥á¥â¥ê¤Î’¤¶¯¤Î»°
tatsunori ishikawa
?
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber
?
swift-nio ¤Î¥¢©`¥­¥Æ¥¯¥Á¥ã©`¤È RxHttpClient
swift-nio ¤Î¥¢©`¥­¥Æ¥¯¥Á¥ã©`¤È RxHttpClient
Shinya Mochida
?
How to stand on the shoulders of giants
How to stand on the shoulders of giants
Ian Barber
?
Rop and it's friends
Rop and it's friends
nuc13us
?
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
Noritada Shimizu
?
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
Joseph Scott
?
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Masahiro Nagano
?
ZeroMQ Is The Answer
ZeroMQ Is The Answer
Ian Barber
?
Formatul Portable Executable
Formatul Portable Executable
DefCamp
?
Commencer avec le TDD
Commencer avec le TDD
Eric Hogue
?
§±§Ú§ê§Ö§Þ §Õ§Ý§ñ asyncio - §¡§ß§Õ§â§Ö§Û §³§Ó§Ö§ä§Ý§à§Ó, PyCon RU 2014
§±§Ú§ê§Ö§Þ §Õ§Ý§ñ asyncio - §¡§ß§Õ§â§Ö§Û §³§Ó§Ö§ä§Ý§à§Ó, PyCon RU 2014
it-people
?
Continuous testing In PHP
Continuous testing In PHP
Eric Hogue
?
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
Ian Barber
?
Guarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous Testing
Eric Hogue
?
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
Nobuo Danjou
?
¥×¥í¥°¥é¥àŒgÐФλ°¤È?°¿³§¤È¥á¥â¥ê¤Î’¤¶¯¤Î»°
¥×¥í¥°¥é¥àŒgÐФλ°¤È?°¿³§¤È¥á¥â¥ê¤Î’¤¶¯¤Î»°
tatsunori ishikawa
?

Similar to Php arduino (20)

Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
Svet Ivantchev
?
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Demetrio Siragusa
?
Introduction to Node MCU
Introduction to Node MCU
Amarjeetsingh Thakur
?
selected input/output - sensors and actuators
selected input/output - sensors and actuators
Eueung Mulyana
?
Arduino coding class part ii
Arduino coding class part ii
Jonah Marrs
?
Sensors and Actuators in Arduino, Introduction
Sensors and Actuators in Arduino, Introduction
BibekPokhrel13
?
IoT with openHAB on pcDuino3B
IoT with openHAB on pcDuino3B
Jingfeng Liu
?
Arduino for Beginners
Arduino for Beginners
Sarwan Singh
?
Cassiopeia Ltd - ESP8266+Arduino workshop
Cassiopeia Ltd - ESP8266+Arduino workshop
tomtobback
?
dotCloud and go
dotCloud and go
Flavio Poletti
?
From clever code to better code
From clever code to better code
Dror Helper
?
Physical Computing with the Arduino platform and Ruby
Physical Computing with the Arduino platform and Ruby
mdweezer
?
Endless fun with Arduino and Eventmachine
Endless fun with Arduino and Eventmachine
Bodo Tasche
?
Introduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
Mujahid Hussain
?
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
hussain0075468
?
Arduino pr¨¢ctico ethernet
Arduino pr¨¢ctico ethernet
Jose Antonio Vacas
?
IoT Hands-On-Lab, KINGS, 2019
IoT Hands-On-Lab, KINGS, 2019
Jong-Hyun Kim
?
Socket Programming Intro.pptx
Socket Programming Intro.pptx
ssuserc4a497
?
Arduino¡¢Web µ½ IoT
Arduino¡¢Web µ½ IoT
Justin Lin
?
Arduino delphi 2014_7_bonn
Arduino delphi 2014_7_bonn
Max Kleiner
?
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
Svet Ivantchev
?
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Demetrio Siragusa
?
selected input/output - sensors and actuators
selected input/output - sensors and actuators
Eueung Mulyana
?
Arduino coding class part ii
Arduino coding class part ii
Jonah Marrs
?
Sensors and Actuators in Arduino, Introduction
Sensors and Actuators in Arduino, Introduction
BibekPokhrel13
?
IoT with openHAB on pcDuino3B
IoT with openHAB on pcDuino3B
Jingfeng Liu
?
Arduino for Beginners
Arduino for Beginners
Sarwan Singh
?
Cassiopeia Ltd - ESP8266+Arduino workshop
Cassiopeia Ltd - ESP8266+Arduino workshop
tomtobback
?
From clever code to better code
From clever code to better code
Dror Helper
?
Physical Computing with the Arduino platform and Ruby
Physical Computing with the Arduino platform and Ruby
mdweezer
?
Endless fun with Arduino and Eventmachine
Endless fun with Arduino and Eventmachine
Bodo Tasche
?
Introduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
Mujahid Hussain
?
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
hussain0075468
?
IoT Hands-On-Lab, KINGS, 2019
IoT Hands-On-Lab, KINGS, 2019
Jong-Hyun Kim
?
Socket Programming Intro.pptx
Socket Programming Intro.pptx
ssuserc4a497
?
Arduino¡¢Web µ½ IoT
Arduino¡¢Web µ½ IoT
Justin Lin
?
Arduino delphi 2014_7_bonn
Arduino delphi 2014_7_bonn
Max Kleiner
?
Ad

Recently uploaded (20)

¡°Why It¡¯s Critical to Have an Integrated Development Methodology for Edge AI,...
¡°Why It¡¯s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
?
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
?
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
?
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
?
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
?
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
?
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
?
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
?
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
?
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
?
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
?
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
?
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
?
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
?
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
?
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
?
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
?
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
?
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
?
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
?
¡°Why It¡¯s Critical to Have an Integrated Development Methodology for Edge AI,...
¡°Why It¡¯s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
?
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
?
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
?
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
?
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
?
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
?
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
?
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
?
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
?
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
?
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
?
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
?
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
?
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
?
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
?
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
?
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
?
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
?
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
?
Ad

Php arduino

  • 1. >_ Things Lab Connecting PHP with Arduino
  • 3. Arduino Code : Part 1 int led = 12; void setup() { // Open serial communications Serial.begin(9600); // send an intro: Serial.println("0=off, 1=on"); Serial.println(); pinMode(led,OUTPUT); }
  • 4. Arduino Code : Part 2 void loop() { // get any incoming bytes: if (Serial.available() > 0) { int input = Serial.read(); if (input == 48) { //received 0 digitalWrite(led,LOW); } else if (input == 49) { //received 1 digitalWrite(led,HIGH); } } }
  • 5. PHP code (same dir as "php_serial.class.php") <?php include "php_serial.class.php"; $msg = $argv[1]; // 0=off, 1=on $serial = new phpSerial; $serial->deviceSet("/dev/ttyUSB0"); $serial->confBaudRate(9600); $serial->confParity("none"); $serial->confCharacterLength(8); $serial->confStopBits(1); $serial->deviceOpen(); if (intval($msg)==0) $serial->sendMessage(0); //turn the led off else $serial->sendMessage(1); //turn the led on $serial->deviceClose(); ?>
  • 6. Running the code ? Upload code into Arduino ? Execute: # get the PHP cli sudo apt-get install php5-cli php test.php [args] # run the program ? Pass 0 to turn the led off, or others to turn it on