一般用什么APP来通过WiFi控制arduino
4个回答
2016-11-25
展开全部
项目需要的硬件如下:
Arduino Uno
Ethernet Shield
LED灯 2个.
电阻 2个.
面包板(可选)
连接导线
路由器一个
项目要的连接管脚如下:
LED 1 --> pin 6 to ground
LED 2 --> pin 7 to ground
项目需要的软件如下:
Eclipse IDE
Arduino IDE 1.x.x
LED 1 --> pin 6 to ground
LED 2 --> pin 7 to ground
项目需要的软件如下:
Eclipse IDE
Arduino IDE 1.x.x
Step 1: 在 Arduino上编程如下:#include "etherShield.h"
#include "ETHER_28J60.h"
int led2 = 7;
int led1 = 6;
static uint8_t mac[6] = {0xAA, 0xBB, 0xCC, 0xDD, 0xBB, 0xAA}; // this just needs to be unique for your network,
// so unless you have more than one of these boards
// connected, you should be fine with this value.
static uint8_t ip[4] = {192, 168, 0, 15}; // the IP address for your board. Check your home hub
// to find an IP address not in use and pick that
// this or 10.0.0.15 are likely formats for an address
// that will work.
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
void setup()
{
e.setup(mac, ip, port);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
void loop()
{
char* params;
if (params = e.serviceRequest())
{
if (strcmp(params, "?cmd=1") == 0)
{
digitalWrite(led1, HIGH);
}
if (strcmp(params, "?cmd=2") == 0)
{
digitalWrite(led1, LOW);
}
if (strcmp(params, "?cmd=3") == 0)
{
digitalWrite(led2, HIGH);
}
if (strcmp(params, "?cmd=4") == 0)
{
digitalWrite(led2, LOW);
}
e.respond();
}
}
Step 2: 制作安卓APP
package com.androidarduino;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.
ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View led1on = findViewById(R.id.led_1on);
View led1off = findViewById(R.id.led_1off);
View led2on = findViewById(R.id.led_2on);
View led2off = findViewById(R.id.led_2off);
led1on.setOnClickListener(this);
led1off.setOnClickListener(this);
led2on.setOnClickListener(this);
led2off.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void commandArduino(String url){
try {
HttpClient httpclient = new DefaultHttpClient();
httpclient.execute(new HttpGet(url));
} catch (Exception e) {
}
}
public void onClick(View thisView) {
switch(thisView.getId()){
case R.id.led_1on:
commandArduino("192.168.0.15/?cmd=1");
Toast.makeText(getApplicationContext(), "led_1on",Toast.LENGTH_LONG).show();
break;
case R.id.led_1off:
commandArduino("192.168.0.15/?cmd=2");
Toast.makeText(getApplicationContext(), "led_1off",Toast.LENGTH_LONG).show();
break;
case R.id.led_2on:
commandArduino("192.168.0.15/?cmd=3");
Toast.makeText(getApplicationContext(), "led_2on",Toast.LENGTH_LONG).show();
break;
case R.id.led_2off:
commandArduino("192.168.0.15/?cmd=4");
Toast.makeText(getApplicationContext(), "led_2off",Toast.LENGTH_LONG).show();
break;
}
}
}
晓网科技
2024-10-17 广告
2024-10-17 广告
广州晓网电子科技有限公司还是挺专业的,广州晓网电子科技有限公司是一家集研发、销售、方案设计为一体的高新技术企业。我们致力于为客户提供无线数据采集,无线网络传输和远程监控解决方案,帮助客户实现智能照明管理,工厂自动化生产数据采集,电子标签人员...
点击进入详情页
本回答由晓网科技提供
展开全部
可以自己设计一个app,用app inventor,然后加入arduino的组件就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
物联网IoT入门 - ESP8266 WiFi模块与Arduino, 通过WiFi控制LED
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
青铜谙妆军烈属毁沿
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询